package com.qf.voterabbitmqcustomer.rabbitmq;

import com.qf.voterabbitmqcustomer.voteLogs.service.IVoteLogsService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.ParseException;

/**
 * @author 刘欣
 * @createTime 2023/3/2 15:04
 * @description 消费vote_queues队列
 */
@Component
@Slf4j
public class VoteLogsCustomer {

    @Autowired
    private IVoteLogsService voteLogsService;

    @RabbitListener(queues = "queue_vote")
    public void getMsg(String msg, Channel channel, Message message) throws IOException, ParseException {
        log.debug("msg={},channel={},message={}", msg, channel, message);
        voteLogsService.saveVoteLogs(msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
